<template>
    <div id="quotation" class="seeDisabled">
        <el-form :inline="true" :model="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <el-form-item label="法人名称" class="selectMB10" :label-width="labelWidth" v-if="!powerFlag">
                <el-select size="mini" disabled v-model="formInline.legalPersonName">
                    <el-option v-for="(legalPerson,index) in legalPersonDropDown" :key="index" :label="legalPerson.legalPersonName" :value="legalPerson.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="报价单号" class="selectMB10" :label-width="labelWidth">
                <el-input size="mini" disabled v-model="formInline.quotationNumber" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="报价日期" class="selectMB10" :label-width="labelWidth">
                <el-input size="mini" disabled v-model="formInline.createTime" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="报价人员" class="selectMB10" :label-width="labelWidth">
                <el-input size="mini" disabled v-model="formInline.bidder" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="报价单位" class="selectMB10" :label-width="labelWidth">
                <el-select size="mini" disabled v-model="formInline.vendor" placeholder="">
                    <el-option v-for="(vendor,index) in formInline.selectDropdown" :key="index" :label="vendor.partnerName" :value="vendor.partnerCode"></el-option>
                </el-select>
            </el-form-item>
             <el-form-item label="报价对象" :label-width="labelWidth" v-if="powerFlag">
                <el-input size="mini" disabled v-model="formInline.legalPersonName" placeholder=""></el-input>
            </el-form-item>
           <!-- <el-form-item label="报价对象" class="selectMB10">
                <el-select size="mini" disabled v-model="formInline.legalPersonId">
                    <el-option v-for="legalPerson in legalPersonDropDown" :label="legalPerson.legalPersonName" :value="legalPerson.legalPersonName"></el-option>
                </el-select>
            </el-form-item>-->
            <!--<el-form-item label="报价类型" class="selectMB10">
                <el-select size="mini" disabled v-model="formInline.biddingType" placeholder="请选择">
                    <el-option v-for="inquiryType in selectDropdown.biddingType" :label="inquiryType.label" :value="inquiryType.value"></el-option>
                </el-select>
            </el-form-item>-->
            <el-form-item label="报价币别" class="selectMB10" :label-width="labelWidth">
                <el-select size="mini" disabled v-model="formInline.currencyCodeWord" placeholder="请选择">
                    <el-option v-for="(inquiryCurrency,index) in selectDropdown.currencyCode" :key="index" :label="inquiryCurrency.label" :value="inquiryCurrency.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="汇率" class="selectMB10" header-align="center" prop="exchangeRate" :label-width="labelWidth">
                <el-input size="mini" disabled v-model.number="formInline.exchangeRate" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="金额是否含税" class="selectMB10" :label-width="labelWidth100">
                <el-select size="mini" disabled v-model="formInline.isTaxName" placeholder="请选择">
                    <el-option v-for="(isIncludeTax,index) in selectDropdown.isTax" :key="index" :label="isIncludeTax.label" :value="isIncludeTax.value"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="报价生效日期" class="selectMB10" :label-width="labelWidth100" prop="startTime" :rules="[{ required: true, message: '报价生效日期不能为空'}]">
                <el-date-picker type="date" size="mini" :editable="false" disabled v-model="formInline.startTime" placeholder="选择报价生效日期" @change="selectedStartTime"></el-date-picker>
                <!-- :picker-options="InquiryBeginsDate" -->
            </el-form-item>
            <el-form-item label="报价失效日期" class="selectMB10" :label-width="labelWidth100" prop="endTime" :rules="[{ required: true, message: '报价失效日期不能为空'}]">
                <el-date-picker type="date" size="mini" :editable="false" disabled v-model="formInline.endTime" placeholder="选择日期" @change="selectedEndTime"></el-date-picker>
                <!-- :picker-options="InquiryEndDate" -->
            </el-form-item>
            <el-form-item label="报价总数量" :label-width="labelWidth100">
                <el-input size="mini" disabled placeholder="" v-model="formInline.totalQuantityQuoted"></el-input>
            </el-form-item>
            <el-form-item label="报价不含税总金额" :label-width="labelWidth120">
                <el-input size="mini" disabled placeholder="" v-model="formInline.totalQuotedPrice"></el-input>
            </el-form-item>
            <el-form-item label="报价含税总金额" :label-width="labelWidth120">
                <el-input size="mini" disabled placeholder="" v-model="formInline.totalQuotedTaxPrice"></el-input>
            </el-form-item>
            <el-form-item class="selectMB10">
                 <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="formInline.biddingStatus == 20" @click="handleReview">审核</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger"  v-if="formInline.biddingStatus == 30" disabled @click="handleReview">审核</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="formInline.biddingStatus == 30"  @click="handleApprove">审批</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger"  v-if="formInline.biddingStatus == 20" disabled @click="handleApprove">审批</el-button>
            </el-form-item>
        </el-form>
        <!--待报价明细表格-->
        <label class="default-label">报价明细：</label>
        <el-button  class="bolder outsideBtnBS" size="mini" type="danger">导出</el-button>
        <el-table :data="inquiryDetailsData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
            <el-table-column prop="spareCoding" property="spareCoding" label="备件编码" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="spareName" property="spareName" label="备件名称" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="measurementUnit" property="measurementUnit" label="计量单位" header-align="center" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="quotedQuantity" property="quotedQuantity" label="报价数量" header-align="center" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="currencyCodeWord" property="currencyCode" label="币别" header-align="center" width="80" show-overflow-tooltip></el-table-column>
            <!--含税单价金额-->
            <el-table-column prop="includingTaxPrice" label="含税单价金额" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column prop="quotationAmount" property="quotationAmount" label="不含税单价金额" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <!--新增税率字段-->
            <el-table-column  label="税率(%)" header-align="center" width="100" prop="taxRate" show-overflow-tooltip></el-table-column>
            <el-table-column prop="quantityAvailable" property="quantityAvailable" label="可供数量" header-align="center" width="120" show-overflow-tooltip></el-table-column>
            <el-table-column prop="moq" property="MOQ" label="MOQ" header-align="center" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="deliveryCycle" property="deliveryCycle" label="交货周期(天)" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="quotationExplain" property="quotationExplain" label="说明" header-align="center" show-overflow-tooltip></el-table-column>

        </el-table>
        <!-- 点击审核 审核弹窗 -->
        <el-dialog title="审核提示信息" :visible.sync="handleReviewVisible" size="small" :lock-scroll="false">
            <el-form :model="reviewForm">
                <h2>是否审核通过当前单据？</h2>
                <el-form-item label="审核意见" :label-width="formLabelWidth">
                    <el-input type="textarea"  :rows="3" placeholder="请输入内容" v-model="reviewForm.textarea">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="toExamine(1)">审核通过</el-button>
                <el-button @click="toExamine(0)">审核不通过</el-button>
            </div>
        </el-dialog>
        <!-- 点击审批 审批弹窗 -->
        <el-dialog id="approvalMask" title="审批提示信息" :visible.sync="handleApprovalVisible" size="small" :lock-scroll="false">
            <el-form :model="approvalForm">
                <h2>是否审批通过当前单据？</h2>
                <el-form-item label="审批意见" :label-width="formLabelWidth">
                    <el-input type="textarea"  :rows="3" placeholder="请输入内容" v-model="approvalForm.textarea">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="examinationAndApproval(1)">审批通过</el-button>
                <el-button @click="examinationAndApproval(0)">审批不通过</el-button>
            </div>
        </el-dialog>
        <!--分页-->
        <el-pagination v-if="isPaging" @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page.sync="currentPage3" :current-page="pageIndex"
                       :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                       :page-count="totalPage" :total="totalNumber">
        </el-pagination>

    </div>
</template>
<script>
    export default {
        data(){
            return{
                labelWidth:"80px",
                labelWidth100:"100px",
                labelWidth120:"120px",
                formInline:{
                    id:'',
                    quotationNum:'',
                    createTime:'',
                    bidder:'',
                    legalPersonId:"",
                    biddingType:"",
                    currencyCode:"",
                    isTax:"",
                    startTime:"",
                    endTime:""
                },
                legalPersonDropDown:[],
                loading:false,
                inquiryDetailsData: [],// 待报价明细表格
                supplierDetails:[],// 待报价供应商明细
                selectDropdown:[],  // 下拉列表的值
                spareData:[],
                formLabelWidth:"90",
                providerList:[],//新增供应商弹框中，选中的供应商的信息
                spareList:[], //新增备件弹框中，选中的备件的信息
                formLabelWidth:"90",

                handleReviewVisible:false,    //审核弹窗
                reviewForm:{      //审核内容
                    textarea:""
                },
                handleApprovalVisible:false,    // 审批弹窗
                approvalForm:{      //审批内容
                    textarea:""
                },
                // 分页
                pageIndex:1,    //当前页（必传）
                pageSize :10,   //每页多少条
                totalNumber: 20,
                totalPage:2,
                isPaging:false,
                
                //权限
                powerFlag:false   //不是业务合作人员

            };
        },
        computed:{
            identity(){
                return this.$store.state.identity;
            }
        },
        watch:{
            identity(){
                var _this=this;
                if(_this.identity == 2){
                    _this.powerFlag = true;   //是业务合作人员
                }
            }
        },
        //进入页面立即运行此方法
        mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'CheckQuotation');
            _this.formInline.quotationNumber=_this.$route.query.quotationNumber;
            if(_this.identity == 2){
                _this.powerFlag = true;   //是业务合作人员
            }

            _this.seeInquiry();  //进入页面直接 查看报价单列表


        },
        methods:{
            //报价生效日期
            selectedStartTime(val){
                var _this=this;
                _this.formInline.startTime = val;
                if(_this.formInline.endTime && val > _this.formInline.endTime){
                    _this.common.errorTip("报价生效日期不能大于报价失效日期");
                    _this.formInline.startTime = "";
                };
            },
            //报价失效日期
            selectedEndTime(val){
                var _this=this;
                _this.formInline.endTime = val;
                if(_this.formInline.startTime && val < _this.formInline.startTime){
                    _this.common.errorTip("报价失效日期不能小于报价生效日期");
                    _this.formInline.endTime = "";
                };
            },
            //审核按钮
            handleReview(){
                var _this=this;
                _this.handleReviewVisible=true;
            },
            toExamine(auditorStatus){   //1 审核通过  0审核不通过
                var _this = this;
                var auditorTime=_this.getTime();
                var tmp = {quotationNumber:_this.formInline.quotationNumber,auditorExplain:_this.reviewForm.textarea,auditorTime:auditorTime,auditorStatus:auditorStatus};
                $.ajax({
                    url:_this.procurement_service+'quotationAuditor/update',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            _this.common.successTip("审核成功！");
                            _this.$router.push("/QuotationSheet");
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 审批按钮
            handleApprove(){
                var _this=this;
                _this.handleApprovalVisible=true;
            },
            examinationAndApproval(approverStatus){ //1 审批通过  0审批不通过
                var _this = this;
                var approverTime=_this.getTime();
                var tmp = {quotationNumber:_this.formInline.quotationNumber,approverExplain:_this.approvalForm.textarea,approverTime:approverTime,approverStatus:approverStatus};
                $.ajax({
                    url:_this.procurement_service+'quotationApprover/update',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            _this.common.successTip("审批成功！");
                            _this.$router.push("/QuotationSheet");
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 获取当前时间
            getTime(){
                var myDate=new Date();
                var year=myDate.getFullYear();
                var month=myDate.getMonth()+1;
                var day=myDate.getDate();
                var hours=myDate.getHours();
                var minutes=myDate.getMinutes();
                var seconds=myDate.getSeconds();
                var time = year +"-"+ month +"-"+ day +" "+ hours +":"+ minutes +":"+ seconds;
                return time;
            },
            //   分页
            handleSizeChange(val) {
                // console.log(`每页 ${val} 条`);
                var _this = this;
                _this.pageSize=val;
                _this.queryByPage(_this.pageIndex, _this.pageSize);
            },
            //点击页码分页查询点击事件
            handleCurrentChange(val) {
                // console.log(`当前页: ${val}`);
                var _this = this;
                _this.pageIndex=val;
                _this.queryByPage(_this.pageIndex, _this.pageSize);
            },
            legalPersonDropDownValue(){  //法人名称下拉列表值
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"legalPerson/ofCurrentUser",
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.legalPersonDropDown = data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            seeInquiry(){   //查看报价单列表
                var _this =this;
                var tmp = {quotationNumber:_this.formInline.quotationNumber};
                $.ajax({
                    url:_this.procurement_service+'quotation/see',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            _this.formInline=data.data[0];
                            console.log(_this.formInline);
                            _this.inquiryDetailsData=data.data[0].quotationItem;
//                            _this.supplierDetails= data.data[0].supplierDetailsList;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            createInquerySheetDropdownValue(){ //下拉列表的值
                var _this =this;
                var tmp = ["type","isTax","currencyCode"];
                $.ajax({
                    type:'POST',
                    url:_this.procurement_service+'procurement/getPullDownList',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:"application/json;charset=utf-8",
                    success: function(data){
                        if(data.success){
                            _this.selectDropdown=data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                });
            },
           
            // //
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: '成功',
            //         message: p,
            //         type: 'success'
            //     });
            // },
            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: '错误',
            //         message: p
            //     });
            // }
        }
    }
</script>